{- QoSWeaver.orc -- Orc program QoSWeaver
 - 
 - $Id$
 - 
 - Created by akattepu on 08-Aug-2012 14:50:38
 -}

def QoSWeaver(site,(lookup,unit,handle)) =
   
   def ResponseTimeCheck(competition) = 
    Ift(lookup = ResponseTime && handle = LatencyIncrement) >> (Ambient(ResponseTime,competition) >> (ResponseTime(unit).QoS(site)))
  
   def CPUutlizationCheck(competition) = 
    Ift(lookup = CPUutilization && handle = CPUutilizationValue) >> (Ambient(CPUutilization,competition) >> (CPUutilization(unit).QoS(site)))
   
   def CostCheck() =
    Ift(lookup = Cost && handle = CostValue) >>  (NonAmbient(Cost) >> Cost(unit).QoS(site,CostValue()))
   
   def SecurityCheck() =
    Ift(lookup= SecurityLevel && handle = SecurityValue) >>  (NonAmbient(SecurityLevel) >> SecurityLevel(unit).QoS(site,SecurityValue()))
   
   def InterQueryCheck() =
    Ift(lookup= InterQueryTime) >>  (NonAmbient(InterQueryTime) >> InterQueryTime(unit).QoS(site))
    
    def ReliabilityCheck() =
    Ift(lookup= Reliability && handle = ReliabilityValue) >>  (NonAmbient(Reliability) >> Reliability(unit).QoS(site,ReliabilityValue()))
   
signal >> v<v<(ResponseTimeCheck(max)| CostCheck() | SecurityCheck() | InterQueryCheck()) |ReliabilityCheck() | CPUutlizationCheck(min)

def QoS(site,identifier) = 
   val Data = Ref()
   def QoSCollect(v) = collect(defer2(QoSWeaver,Data?,v))
site >d> Data:=d >> collect(defer(QoSMatch,identifier)) >v> (Data?, map(QoSCollect,v))